﻿using System.Linq.Expressions;

namespace S.Api.Core
{
    /// <summary>
    /// 实现增删改查的接口 用于快速搭建基于领域的api
    /// </summary>
    public interface ICurdService<T> where T : class
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"> </param>
        /// <returns> </returns>
        bool Add(T model);

        /// <summary>
        /// 删除（物理删除）
        /// </summary>
        /// <param name="model"> </param>
        /// <returns> </returns>
        bool Delete(object id);

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="model"> </param>
        /// <returns> </returns>
        bool Update(object id, ParameterModel model);

        /// <summary>
        /// 设置flag属性
        /// </summary>
        /// <param name="model"> </param>
        /// <returns> </returns>
        bool SetFlag(object id, ParameterModel model);

        #region 查询类

        /// <summary>
        /// 获取单个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T? Get(object id);

        /// <summary>
        /// 获取单个
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        T? Get(Expression<Func<T, bool>> where);

        /// <summary>
        /// 获取单个
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        T? Get(List<Filter> filters);

        /// <summary>
        /// 条件分页
        /// </summary>
        /// <param name="parameter"> </param>
        /// <returns> </returns>
        ApiPageResult<T> Page(PageQueryDto pageQueryDto);

        /// <summary>
        ///条件查询
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        ApiListResult<T> List(List<Filter> filters);

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        List<T> List(Expression<Func<T, bool>> where);
        #endregion 查询类
    }
}
